package com.lucky.carcodepro.exception;

import com.lucky.carcodepro.domain.enums.ResponseStatusEnums;
import lombok.Getter;
import lombok.Setter;

/**
 * BusinessException
 * <p>
 * 描述：
 *
 * @author Annie
 * @version 2024/10/2 14:36
 */

public class BusinessException extends RuntimeException
{

    private static final long serialVersionUID = 1L;
    @Getter
    private String code;

    @Getter
    private String msg;

    /**
     * 是否打印对战信息
     */
    @Getter
    @Setter
    private Boolean ifDz = false;

    public BusinessException(ResponseStatusEnums enums)
    {
        this(enums, enums.getMsg());
        this.code = enums.getCode();
        this.msg = enums.getMsg();
    }

    public BusinessException(ResponseStatusEnums enums, String msg)
    {
        super(getAllMsg(enums.getCode(), msg));
        this.code = enums.getCode();
        this.msg = msg;
    }

    public BusinessException(ResponseStatusEnums enums, String s, Object... o)
    {
        this(enums, String.format(s, o));
    }

    private static String getAllMsg(String code, String msg)
    {
        return code + "--" + msg;
    }

}
